package com.dzm.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dzm.entity.Student;
import com.dzm.service.StudentService;
import com.dzm.mapper.StudentMapper;
import com.dzm.vo.SearchVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @author Dzm
* @description 针对表【student】的数据库操作Service实现
* @createDate 2024-08-21 11:00:15
*/
@Service
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student>
    implements StudentService{

    @Autowired
    private StudentMapper studentMapper;

    @Override
    public Page<Student> searchStudent(Integer pageNum, Integer pageSize, SearchVo vo) {
        LambdaQueryWrapper<Student> wrapper = new LambdaQueryWrapper<>();
        if(vo != null) {
            wrapper.like(StrUtil.isNotBlank(vo.getSname()), Student::getSname, vo.getSname())
                    .like(StrUtil.isNotBlank(vo.getAddr()), Student::getAddr, vo.getAddr())
                    .eq(vo.getCid() != null && vo.getCid() != 0, Student::getCid, vo.getCid());
        }

        Page<Student> page = this.page(new Page<>(pageNum, pageSize), wrapper);


        return page;
    }
}




